package cn.vc.auth.controller;

import cn.vc.basicmodule.entity.Result;
import cn.vc.auth.service.CaptchaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.mail.MessagingException;

/**
 * 验证码接口
 */
@Slf4j
@RestController
@RequestMapping("/captcha")
public class CaptchaController {
    @Resource
    private CaptchaService captchaService;


    /**
     * 发送验证码
     * @param email 电子邮箱
     * @param prefix 前缀（用来分辨用途）
     */
    @PostMapping("/{email}/{prefix}")
    public Result<?> sendCaptcha(@PathVariable("email") String email, @PathVariable("prefix") String prefix) throws MessagingException {
        String captcha = captchaService.sendCaptcha(email, prefix);
        log.info("发送验证码："+email+"_"+prefix+" -> "+captcha);
        return new Result<>(captcha!=null?1:0);
    }
}
